﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text.RegularExpressions;
using System.Collections;
using Isha;
using Isha.Entities;
using Isha.Infrastructure;
using Isha.Web.Mvc;

namespace System.Web.Mvc
{
    public static class HtmlExtensions
    {
        public static MvcHtmlString Html(this HtmlHelper _helper)
        {
            string name = Regex.Replace(_helper.ViewDataContainer.ToString().ToLower(),
                "ASP._Page_Views_|_cshtml|_vbhtml|part_", "", RegexOptions.IgnoreCase);
           
            Part part = IshaContext.Current.Parts.Where(p => p.Name.Contains(name)).FirstOrDefault();

            if (part != null)
            {               
                return new MvcHtmlString(part.Html);
            }
            else
            {
                return new MvcHtmlString("");
            }
        }
    }
}